<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 先引入核心库 -->
    <script src="./js/react.development.js"></script>
    <!-- 再引入拓展库 用于react支持dom操作 -->
    <script src="./js/react-dom.development.js"></script>
    <!-- 引入jsx转js库 -->
    <script src="./js/babel.min.js"></script>
</head>

<body>
    <div id="test"></div>
    <!-- //此处一定要写babel -->
    <script type="text/babel">
        class Mything extends React.Component {
            state= {
                username:'',
            }
            // demo = (event) =>{
            //     this.setState({username:event.target.value})
            // }
            demo =(dataType) =>{
                return (event)=>{
                    this.setState({[dataType]:event.target.value})
                }
            }
            
            handleSubmit = (event) =>{
                event.preventDefault() //阻止表单提交
                alert(`id是${this.state.username}`)
            }

            render(){
                return (
                    <form onSubmit={this.handleSubmit}>
                        id：<input onChange={this.demo('username')} type="text" name="username"/>
                        <button>提交</button>
                    </form>
                )
            }
        }
        ReactDOM.render(<Mything/>, document.querySelector('#test'))
    </script>
</body>

</html>